package com.shaozj.core.utils.ip;

import cn.hutool.core.net.NetUtil;
import cn.hutool.http.HtmlUtil;
import com.shaozj.core.utils.StringUtil;

/**
 *  获取地址工具类
 */
public class AddressUtil {

    // 未知地址
    public static final String UNKNOWN = "XX XX";

    public static String getRealAddressByIP(String ip) {
        if (StringUtil.isEmpty(ip)) {
            return UNKNOWN;
        }
        //内网IP不查询
        ip = StringUtil.contains(ip, "0:0:0:0:0:0:0:1") ? "127.0.0.1" : HtmlUtil.cleanHtmlTag(ip);
        if (NetUtil.isInnerIP(ip)) {
            return "内网IP";
        }
        return RegionUtil.getCityInfo(ip);
    }
}
